﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using vnBiometricsSDK.FingerPrint;
using vnFingerPrint;

namespace vnBiometricsSDK.FingerPrint
{
    public class vnSumarySDK
    {
        public static Bitmap LayAnhXuong(Bitmap bmpGray)
        {
            CFingerPrint vantay = new CFingerPrint();
            vantay.setFingerPrintImage(bmpGray);
            double[] dactrung = vantay.getFingerPrintTemplate();
            return vantay.getFingerPrintImageDetail(Color.Black, false);
        }
        public static double[] LayDacTrung(Bitmap bmpGray)
        {
            CFingerPrint vantay = new CFingerPrint();
            vantay.setFingerPrintImage(bmpGray);
            double[] dactrung = vantay.getFingerPrintTemplate();
            return dactrung;
        }
        public static double[] LayDacTrungANN(Bitmap bmpGray)
        {
            CFingerPrint vantay = new CFingerPrint();
            vantay.setFingerPrintImage(bmpGray);
            double[] dactrung = vantay.getFingerPrintTemplate();
            double[] dacTrungAnn = new double[dactrung.Length];

            return dactrung;
        }

        public static string LayDacTrungString(Bitmap bmpGray)
        {
            CFingerPrint vantay = new CFingerPrint();
            vantay.setFingerPrintImage(bmpGray);
            double[] dactrung = vantay.getFingerPrintTemplate();
            return vantay.ConvertFingerPrintTemplateDoubleToString(dactrung);
        }
        public static string LayDacTrungString(Bitmap bmpGray,out string CoreDelta)
        {
            CFingerPrint vantay = new CFingerPrint();
            vantay.setFingerPrintImage(bmpGray);
            double[] dactrung = vantay.getFingerPrintTemplate();
            CoreDelta=vantay.Core.X+";"+vantay.Core.Y+";"+vantay.DeltaR.X+";"+vantay.DeltaR.Y+";"+vantay.DeltaL.X+";"+vantay.DeltaL.Y;
            return vantay.ConvertFingerPrintTemplateDoubleToString(dactrung);
        }

        public static Bitmap LayAnhDacTrung(Bitmap bmpGray)
        {
            CFingerPrint vantay = new CFingerPrint();
            vantay.setFingerPrintImage(bmpGray);
            double[] dactrung = vantay.getFingerPrintTemplate();
            return vantay.getFingerPrintImageDetail(Color.Black, true);
        }
        public static Bitmap LayAnhXuongDacTrung(Bitmap bmpGray)
        {
            CFingerPrint vantay = new CFingerPrint();
            vantay.setFingerPrintImage(bmpGray);
            double[] dactrung = vantay.getFingerPrintTemplate();
            return vantay.getFingerPrintImageDetail(Color.Black, true);
        }
        public static Bitmap Gabor(Bitmap bmpGray)
        {
            matrannguyen mt = new matrannguyen(512,512);
            mt.DocBitmap(bmpGray);
            mt.gabor();
            return mt.ToBitmap();
        }
        public static Bitmap CaiThienAnh(Bitmap bmpGray)
        {
            matrannguyen mt = new matrannguyen(512, 512);
            mt.DocBitmap(bmpGray);
            mt=mt.loctrungvi(3);
            //mt=mt.gabor();
            mt = mt.gabor();
            mt = mt.loctrungvi(3);
            mt=mt.nhiphan();
            //Bitmap bmp = vnImageProcess.ConvertToGrayscale(mt.ToBitmap());
            // bmp = vnImageProcess.Wiener(bmp);
            return mt.ToBitmap();
        }
        public static int PhanTramPhuHop(double[] dactrung1, double[] dactrung2)
        {
            CFingerPrint f_match=new CFingerPrint();
            int i, j;
            i= f_match.Match(dactrung1, dactrung2, 80, false);
            j = f_match.Match(dactrung2, dactrung1, 80, false);
            if (i > j) return i;
            return j;
        }
        public static int PhanTramPhuHop(string str_dactrung1, double[] dactrung2)
        {
            double[] dactrung1 = new CFingerPrint().ConvertFingerPrintTemplateStringToDouble(str_dactrung1);
            CFingerPrint f_match = new CFingerPrint();
            int i, j;
            i = f_match.Match(dactrung1, dactrung2, 80, false);
            j = f_match.Match(dactrung2, dactrung1, 80, false);
            if (i > j) return i;
            return j;
        }

        internal static Bitmap LayAnhDacTrungANN(Bitmap anhNhiPhan)
        {
            CFingerPrint vantay = new CFingerPrint();
            vantay.setFingerPrintImage(anhNhiPhan);
            double[] dactrung = vantay.getFingerPrintTemplate();
            return vantay.getFingerPrintImageDetailInputANN(Color.Black);
        }
    }
}
